package com.hr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hr.entity.HumanFile;
import com.hr.entity.HumanFileDig;
import com.hr.mapper.HumanFileDigMapper;
import com.hr.service.HumanFileDigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HumanFileDigServiceImpl implements HumanFileDigService {
    @Autowired
    private HumanFileDigMapper humanFileDigMapper;


    @Override
    public Page<HumanFileDig> queryList(Page<HumanFileDig> page,HumanFileDig humanFileDig) {
        //查询条件
        QueryWrapper<HumanFileDig> queryWrapper = new QueryWrapper<HumanFileDig>();
        if(!humanFileDig.getFirstKindId().isEmpty() && humanFileDig.getFirstKindId() != null){
            queryWrapper.eq("first_kind_id",humanFileDig.getFirstKindId());
        }
        if(!humanFileDig.getSecondKindId().isEmpty() && humanFileDig.getSecondKindId() != null){
            queryWrapper.eq("second_kind_id",humanFileDig.getSecondKindId());
        }
        if(!humanFileDig.getThirdKindId().isEmpty() && humanFileDig.getThirdKindId() != null){
            queryWrapper.eq("third_kind_id",humanFileDig.getThirdKindId());
        }
        if(!humanFileDig.getHumanName().isEmpty() && humanFileDig.getHumanName() != null){
            queryWrapper.like("human_name",humanFileDig.getHumanName());
        }
        if(humanFileDig.getHumanFileStatus() != null){
            queryWrapper.eq("human_file_status",humanFileDig.getHumanFileStatus());
        }
        if(humanFileDig.getRegistTime() != null){
            queryWrapper.between("regist_time","1990-01-01",humanFileDig.getRegistTime());
        }
        page = humanFileDigMapper.selectPage(page, queryWrapper);
        System.out.println(page);
        return page;
    }

    @Override
    public boolean save(HumanFileDig humanFileDig) {
        int rows = 0;
        if(humanFileDig.getHufid() == null){
            rows = humanFileDigMapper.insert(humanFileDig);
        }else{
            rows = humanFileDigMapper.updateById(humanFileDig);
        }
        return rows > 0;
    }

    @Override
    public boolean delete(Integer hufid) {
        int i = humanFileDigMapper.deleteById(hufid);
        return i > 0;
    }

    @Override
    public HumanFileDig queryById(Integer hufid) {
        HumanFileDig humanFileDig = humanFileDigMapper.selectById(hufid);
        return humanFileDig;
    }
}
